package com.goodomen.garbage.common.utils;

import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.*;

/**
 * @author : Zhao Da
 * @since : 2019/11/27 11:43
 */
public class ThreadPool {

    private static final ThreadFactory THREAD_FACTORY = new ThreadFactoryBuilder()
            .setNameFormat("indicator-pool-%d").build();

    private static final ExecutorService EXECUTOR_POOL = new ThreadPoolExecutor(2, 4, 60L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(256), THREAD_FACTORY, new ThreadPoolExecutor.AbortPolicy());

    public static void executeThreadPool(Runnable thread) {
        EXECUTOR_POOL.execute(thread);
    }

    public static void shutdownThreadPool() {
        EXECUTOR_POOL.shutdown();
    }
}
